<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/template/template.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">
		<link rel="stylesheet"
			href="/resources/plugins/datatables/dataTables.bootstrap.css" />
		<style>
</style>
	</ui:define>
	<ui:define name="content">
		<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
			<p:commandButton value="是" type="button"
				styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
			<p:commandButton value="否" type="button"
				styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
		</p:confirmDialog>
		<div class='full-center-content-scroll-noheader'>
			<h:form id="form">
				<p:growl id="msgs" showDetail="true" />
				<div class="box box-solid with-border">
					<div class="box-header">
						<p:outputLabel value="电压等级：" style="margin-right:5px;" />
						<h:selectOneMenu id="vol"
							value="#{substationLedgerController.selectdStandVolLevel}"
							style="width:100px;height:30px;margin-right:15px;">
							<f:selectItem itemLabel="全部" itemValue="" />
							<f:selectItems var="vol" value="#{ledgerQueryDataController.standVoltageLevels}"
									itemLabel="#{vol.label}" itemValue="#{vol.value}" />
						</h:selectOneMenu>
						<p:outputLabel value="变电站名称：" style="margin-right:5px;"/>
						<p:autoComplete id="stationSearch" dropdown="true"
							placeholder="变电站首字母查询" scrollHeight="400" size="18"
							value="#{substationLedgerController.equipmentName}"
							style="margin-right:15px;"
							completeMethod="#{cimUtilController.completeCimStation}">
						</p:autoComplete>
						<p:commandButton icon="ui-icon-search" value="查询" onclick="closeDivClick();"
							actionListener="#{substationLedgerController.initSubstationLedgerTable()}"
							update="form:table" style="margin-left:5px;" />
						<p:commandButton icon="ui-icon-refresh" value="重置" onclick="closeDivClick();"
							actionListener="#{substationLedgerController.resetQueryCondition}"
							update="form:table form:dispatchUnit_id form:maintenanceUnit_id form:assetOwner_id form:primary_id form:secondary_id form:stationSearch form:vol"
							style="margin-left:5px;" />
						<div class="box-tools pull-right">
							<button type="button" id="selectButton" title="高级查询"
								class="btn btn-default" onclick="onSelectDivClick();"
								style="margin-right:10px;">
								<span id="selectButtonIcon" class="fa fa-caret-down">高级查询</span>
							</button>
						</div>
					</div>
					<div class="panel-collapse collapse" id="selectDiv" style="margin-left:10px">
						<h:panelGrid columns="6" style="margin-top:8px;margin-bottom:10px" cellpadding="6">
							<p:outputLabel value="调管单位：" style="margin-right:5px;margin-bottom:5px;" />
							<p:autoComplete dropdown="true" id="dispatchUnit_id"
								value="#{substationLedgerController.queryLedger.dispatchUnit}"
								style="margin-right:10px;margin-bottom:5px;" size="18"
								scrollHeight="200" placeholder="输入拼音首字母查询"
								completeMethod="#{ledgerQueryDataController.completeDispatchUnit}">
							</p:autoComplete>
							<p:outputLabel value="运维单位：" style="margin-right:5px;margin-bottom:5px;" />
							<p:autoComplete dropdown="true" id="maintenanceUnit_id"
								value="#{substationLedgerController.queryLedger.maintenanceUnit}"
								style="margin-right:10px;margin-bottom:5px;" size="18"
								scrollHeight="200" placeholder="输入拼音首字母查询"
								completeMethod="#{ledgerQueryDataController.completeMaintenanceUnit}">
							</p:autoComplete>
							<p:outputLabel value="资产归属：" style="margin-right:5px;margin-bottom:5px;" />
							<p:autoComplete dropdown="true" id="assetOwner_id"
								value="#{substationLedgerController.queryLedger.assetOwner}"
								style="margin-right:10px;margin-bottom:5px;" size="18"
								scrollHeight="200" placeholder="输入拼音首字母查询"
								completeMethod="#{ledgerQueryDataController.completeAssetOwner}">
							</p:autoComplete>
						</h:panelGrid>
						<h:panelGrid columns="4" style="margin-top:8px;margin-bottom:10px" cellpadding="6">
							<p:outputLabel value="一次设备检修范围："  style="margin-right:5px;margin-bottom:5px;"/>
							<p:autoComplete dropdown="true" id="primary_id"
								value="#{substationLedgerController.queryLedger.primaryEquipmentScope}"
								style="margin-right:15px;margin-bottom:5px;" size="18"
								scrollHeight="200" placeholder="输入拼音首字母查询"
								completeMethod="#{ledgerQueryDataController.completePrimaryAndSecondaryScope}">
							</p:autoComplete>
							<p:outputLabel value="二次设备检修范围：" style="margin-right:5px;margin-bottom:5px;"/>
							<p:autoComplete dropdown="true" id="secondary_id"
								value="#{substationLedgerController.queryLedger.secondaryEquipmentScope}"
								style="margin-right:15px;margin-bottom:5px;" size="18"
								scrollHeight="200" placeholder="输入拼音首字母查询"
								completeMethod="#{ledgerQueryDataController.completePrimaryAndSecondaryScope}">
							</p:autoComplete>
						</h:panelGrid>
					</div>
				</div>
				<p:toolbar id="toolbar">
					<f:facet name="left">
						<p:commandButton value="编辑" icon="ui-icon-pencil" id="editBtn" actionListener="#{substationLedgerController.preEdit()}"
							rendered="#{s:hasPermission(session,'jcsj_sjwh_bdzgldwwh_bj')}"
							disabled="#{substationLedgerController.selectedStationledgerList.size() == 0}"
							oncomplete="PF('editDlg').show()" update=":editForm:editDlg"
							style="margin-right:5px"  />
						<p:commandButton id="delBtn" icon="ui-icon-trash" value="清除单位设置"
							rendered="#{s:hasPermission(session,'jcsj_sjwh_bdzgldwwh_qcsz')}"
							disabled="#{substationLedgerController.selectedStationledgerList.size() == 0}"
							actionListener="#{substationLedgerController.cleanLedgers}"
							update="form:table form:msgs form:editBtn form:delBtn"
							style="margin-right:5px" >
							<p:confirm header="提示" message="确定清除所选记录的所有单位设置吗?"
								icon="ui-icon-alert" />
						</p:commandButton>
						<p:commandButton value="下载模板" ajax="false"
							rendered="#{s:hasPermission(session,'jcsj_sjwh_bdzgldwwh_xzmb')}"
							icon="ui-icon-arrowthick-1-s"
							actionListener="#{substationLedgerController.fileDownloadView()}"
							style="margin-right:5px" >
							<p:fileDownload value="#{substationLedgerController.templateFile}" />
						</p:commandButton>
						<p:commandButton id="newStatBtn" value="上传文件" icon="ui-icon-arrowthick-1-n"
							rendered="#{s:hasPermission(session,'jcsj_sjwh_bdzgldwwh_scwj')}"
							actionListener="#{substationLedgerController.openUploadDialog}"
							style="margin-right:5px" >
							<p:ajax event="dialogReturn" update="form:msgs form:table"
								listener="#{substationLedgerController.onSelectorChosen}" />
						</p:commandButton>
						<p:commandButton value="初始化数据" icon="ui-icon-refresh" id="initBtn" actionListener="#{substationLedgerController.initDate()}"
							rendered="#{s:hasPermission(session,'jcsj_sjwh_bdzgldwwh_cshsj')}"
							update="form:table" />
					</f:facet>
				</p:toolbar>
				<p:dataTable id="table" var="item" rowKey="#{item.id}"
					emptyMessage="无记录" rowIndexVar="ite" 
					value="#{substationLedgerController.model}"
					selection="#{substationLedgerController.selectedStationledgerList}"
					lazy="true" rows="20" paginator="true" paginatorPosition="bottom"
					paginatorTemplate="{Customization} {CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					rowsPerPageTemplate="20,50,100">
					<f:facet name="{Customization}">
						<p:outputLabel
							value="总计：#{substationLedgerController.rowCount} 条记录"
							style="margin-right:20px;" />
					</f:facet>
					<p:ajax event="rowSelectCheckbox" process="@all" update="form:editBtn form:delBtn" />
					<p:ajax event="rowUnselectCheckbox" process="@all" update="form:editBtn form:delBtn"/>
					<p:ajax event="rowSelect" process="@all" update="form:editBtn form:delBtn"/>
					<p:column selectionMode="multiple"
						style="text-align:center;width:50px" />
					<p:column headerText="序号" width="4%">
						<h:outputText value="#{ite+1}" />
					</p:column>
					<p:column headerText="变电站名称" width="10%">
						<h:outputText value="#{item.name}" />
					</p:column>
					<p:column headerText="调管单位" width="10%">
						<h:outputText value="#{item.dispatchUnit}" />
					</p:column>
					<p:column headerText="运维单位" width="10%">
						<h:outputText value="#{item.maintenanceUnit}" />
					</p:column>
					<p:column headerText="单位类型" width="10%">
						<h:outputText value="#{item.unitType}" />
					</p:column>
					<p:column headerText="资产归属" width="10%">
						<h:outputText value="#{item.assetOwner}" />
					</p:column>
					<p:column headerText="一次设备检修范围" width="10%">
						<h:outputText value="#{item.primaryEquipmentScope}" />
					</p:column>
					<p:column headerText="一次设备检修范围备注" width="10%">
						<h:outputText value="#{item.primaryEquipmentScopeRemark}" />
					</p:column>
					<p:column headerText="二次设备检修范围" width="10%">
						<h:outputText value="#{item.secondaryEquipmentScope}" />
					</p:column>
					<p:column headerText="二次设备检修范围备注" width="10%">
						<h:outputText value="#{item.secondaryEquipmentScopeRemark}" />
					</p:column>
				</p:dataTable>
			</h:form>
			<h:form id="editForm">
				<p:dialog widgetVar="editDlg" id="editDlg" width="500px"
					height="500px" header="编辑">
					<p:toolbar>
						<f:facet name="left">
							<p:commandButton value="保存" update="form"
								icon="ui-icon-disk" oncomplete="PF('editDlg').hide()"
								actionListener="#{substationLedgerController.save}" />
						</f:facet>
					</p:toolbar>
					<p:outputPanel style="width:100%;">
						<p:panelGrid style="width:100%;">
							<p:row>
								<p:column>
									<h:outputText value="变电站名称" />
								</p:column>
								<p:column>
									<ui:repeat value="#{substationLedgerController.selectedStationledgerList}" var="ledger">
										<h:outputText value="#{ledger.name}" style="display:block"/>
									</ui:repeat>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="调管单位" />
								</p:column>
								<p:column>
									<p:inputText id="orgDept" value="#{substationLedgerController.editLedger.dispatchUnit}" readonly="true"/>
									<p:commandButton value="选择" style="margin-left:5px"
										actionListener="#{ledgerQueryDataController.getDesorgDepartDialog()}" >
										<p:ajax event="dialogReturn" listener="#{substationLedgerController.onDesorgDepartChosen}"
											update="editForm:orgDept" />
									</p:commandButton>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="资产归属" />
								</p:column>
								<p:column>
									<p:autoComplete scrollHeight="300" dropdown="true" style="width:75%"
										value="#{substationLedgerController.editLedger.assetOwner}"
										completeMethod="#{ledgerQueryDataController.completeAssetOwnerWhenEdit}">
									</p:autoComplete>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="运维单位" />
								</p:column>
								<p:column>
									<p:inputText id="opCompanyDept" value="#{substationLedgerController.editLedger.maintenanceUnit}" readonly="true"/>
									<p:commandButton value="选择" style="margin-left:5px"
										actionListener="#{ledgerQueryDataController.getOpDepartDialog()}" >
										<p:ajax event="dialogReturn" listener="#{substationLedgerController.onOpDepartChosen}"
											update="opCompanyDept unitType" />
									</p:commandButton>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="单位类型" />
								</p:column>
								<p:column>
									<p:autoComplete scrollHeight="300" dropdown="true" style="width:75%"
										value="#{substationLedgerController.editLedger.unitType}" id="unitType"
										completeMethod="#{ledgerQueryDataController.completeUnitType}">
									</p:autoComplete>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="一次设备检修范围" />
								</p:column>
								<p:column>
									<p:inputText id="primary" value="#{substationLedgerController.editLedger.primaryEquipmentScope}" readonly="true"/>
									<p:commandButton value="选择" style="margin-left:5px"
										actionListener="#{ledgerQueryDataController.getPrimaryAndSecondaryScopeSelectDialog()}" >
										<p:ajax event="dialogReturn" listener="#{substationLedgerController.onPrimaryScopeChosen}"
											update="primary" />
									</p:commandButton>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="一次设备检修范围备注" />
								</p:column>
								<p:column>
									<p:inputText value="#{substationLedgerController.editLedger.primaryEquipmentScopeRemark}" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="二次设备检修范围" />
								</p:column>
								<p:column>
									<p:inputText id="secondary" value="#{substationLedgerController.editLedger.secondaryEquipmentScope}" readonly="true"/>
									<p:commandButton value="选择" style="margin-left:5px"
										actionListener="#{ledgerQueryDataController.getPrimaryAndSecondaryScopeSelectDialog()}" >
										<p:ajax event="dialogReturn" listener="#{substationLedgerController.onSecondryScopeChosen}"
											update="secondary" />
									</p:commandButton>
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputText value="二次设备检修范围备注" />
								</p:column>
								<p:column>
									<p:inputText value="#{substationLedgerController.editLedger.secondaryEquipmentScopeRemark}" />
								</p:column>
							</p:row>
						</p:panelGrid>
					</p:outputPanel>
				</p:dialog>
			</h:form>
		</div>
	</ui:define>
	<ui:define name="contentend">
		<script>
			function onSelectDivClick() {
				var div = $('#selectDiv');
				if (div.hasClass('in')) {
					div.collapse('hide');
					$('#selectButtonIcon').removeClass("fa fa-caret-up");
					$('#selectButtonIcon').addClass("fa fa-caret-down");
				} else {
					div.collapse('show');
					$('#selectButtonIcon').removeClass("fa fa-caret-down");
					$('#selectButtonIcon').addClass("fa fa-caret-up");
				}
			}
			function closeDivClick() {
				var div = $('#selectDiv');
				div.collapse('hide');
				$('#selectButtonIcon').removeClass("fa fa-caret-up");
				$('#selectButtonIcon').addClass("fa fa-caret-down");
			}
		</script>
	</ui:define>
</ui:composition>
